<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="联系人" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入联系人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="店铺类型" prop="isType">
        <el-select v-model="queryParams.isType" placeholder="请选择类型" @change="shopType">
          <el-option
            v-for="item in shopList"
            :key="item.id"
            :label="item.title"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
<!--      <el-form-item label="是否发布" prop="isRelease">-->
<!--        <el-select v-model="queryParams.isRelease" placeholder="请选择是否发布">-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.sys_yes_no"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          ></el-option>-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--      <el-button-->
<!--        type="primary"-->
<!--        plain-->
<!--        icon="el-icon-plus"-->
<!--        size="mini"-->
<!--        @click="uploadFile"-->
<!--      >上传csv数据</el-button>-->
<!--    </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="aHousingList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="标题" align="center" prop="areaDetails" />
      <el-table-column label="店铺类型" align="center" prop="isType" >
        <template slot-scope="scope">
          <div v-if="scope.row.isType == 1" >商铺</div>
          <div v-if="scope.row.isType == 2" >厂房</div>
          <div v-if="scope.row.isType == 3" >档口</div>
          <div v-if="scope.row.isType == 4" >仓库</div>
          <div v-if="scope.row.isType == 5" >找店</div>
        </template>
      </el-table-column>
      <el-table-column label="联系人" align="center" prop="name" />
      <el-table-column label="联系电话" align="center" prop="phone" />
      <el-table-column label="地区" align="center" prop="regionAllName" />
      <el-table-column label="发布时间/支付时间" align="center" prop="payTime" >
        <template slot-scope="scope">
            <span>{{ parseTime(scope.row.payTime, '{y}-{m}-{d} {h}:{i}:{s}' ) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="图片" align="center" prop="picture" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.picture" :width="50" :height="50"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="是否支付" align="center" prop="isPay" width="100">-->
<!--        <template slot-scope="scope">-->
<!--          <div v-if="scope.row.isPay == 0" >已支付</div>-->
<!--          <div v-if="scope.row.isPay == 1" >未支付</div>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="状态" align="center" prop="isPay">
        <template slot-scope="scope">
          <div v-if="scope.row.isPay == 0" style="color:green;">正常支付</div>
          <div v-if="scope.row.isPay == 2" style="color:blue;">手动录入</div>
        </template>
      </el-table-column>
      <el-table-column label="是否上线" align="center" prop="isShow" >
        <template slot-scope="scope">

          <el-switch
            v-model="scope.row.isShow"
            active-color="#13ce66"
            inactive-color="#ff4949"
            active-value="0"
            inactive-value="1"
            active-text="正常"
            inactive-text="停用"
            @change="handleChangeIsShow(scope.row)">
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="是否喜报" align="center" prop="isShow" >
        <template slot-scope="scope">

          <el-switch
            v-model="scope.row.isGood"
            active-color="#13ce66"
            inactive-color="#ff4949"
            active-value="0"
            inactive-value="1"
            active-text="显示"
            inactive-text="关闭"
            @change="handleChangeIsShow(scope.row)">
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="排序" align="center" prop="numSoft" >
        <template slot-scope="scope">
          <el-input-number v-model="scope.row.numSoft" @change="handleChange(scope.row)" :min="1" :max="9999" label="排序" size="mini"></el-input-number>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="updateTimeBtn(scope.row)"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="backIsPay(scope.row)"-->
<!--          >还原未支付</el-button>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改房屋信息对话框 -->
    <el-dialog :title="title" v-loading.fullscreen.lock="loading" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="店铺类型" prop="isType">
          <el-select v-model="form.isType" placeholder="请选择类型" @change="shopType">
            <el-option
              v-for="item in shopList"
              :key="item.id"
              :label="item.title"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="联系人" prop="name">
          <el-input v-model="form.name" placeholder="请输入联系人"  />
        </el-form-item>
        <el-form-item label="联系电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="所在区域" prop="region">
          <el-cascader @change ="areaBtn"
            clearable
            filterable
            show-all-levels
            v-model="form.regionList"
            :props="{expandTrigger: 'hover', value: 'id', label: 'label', disabled: 'disabled', 'emitPath': true, 'checkStrictly': false}"
            :options="iwebshopAreasList"></el-cascader>
        </el-form-item>
        <el-form-item label="图片" prop="picture" v-if="form.isType != 5">
          <image-upload v-model="form.picture" :limit="9" fileRatio="1:1" :fileType="['png','jpg','jpeg']"/>
        </el-form-item>
        <el-form-item label="视频" prop="video" v-if="form.isType != 5">
          <image-upload v-model="form.video" :limit="1" fileRatio="1:1" :fileType="['mp4']"/>
        </el-form-item>
        <el-form-item label="房源类型" prop="isShop" v-if="form.isType == 5">
          <el-select v-model="form.isShop" placeholder="请选择类型" @change="shopType">
            <el-option
              v-for="item in fourList"
              :key="item.id"
              :label="item.title"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="房屋类型" prop="natureId">
          <el-select v-model="form.natureId" placeholder="请选择类型" @change="natureBtn">
            <el-option
              v-for="item in typeListHg"
              :key="item.id"
              :label="item.title"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="房源用途" prop="meetingId"  v-if="form.isType != 5">
          <el-cascader @change="affBtn"
            clearable
            filterable
            v-model="industryIdList"
            :props="{expandTrigger: 'hover', value: 'id', label: 'inName', disabled: 'disabled', 'emitPath': true, 'checkStrictly': false}"
            :options="affiliationList"></el-cascader>
        </el-form-item>

        <el-form-item label="设施优势" prop="advanageId">
          <el-checkbox-group v-model="form.adList" @change="handleCheckedCitiesChange">
            <el-checkbox v-for="ite in advantageList" :label="ite.id" :key="ite.id">{{ite.title}}</el-checkbox>
          </el-checkbox-group>

        </el-form-item>
        <el-form-item label="是否急转" prop="isQuick">
          <el-select v-model="form.isQuick" placeholder="请选择是是否急转">
            <el-option
              v-for="dict in dict.type.sys_yes_no"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="转让出租" prop="isLease" v-if="form.isType != 5">
          <el-select v-model="form.isLease" placeholder="请选择转让出租">
            <el-option
              v-for="dict in dict.type.lease_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="面积" prop="areaNum" v-if="form.isType != 5" >
          <el-input v-model="form.areaNum" placeholder="请输入面积" @change="areaBtnNum"/>
        </el-form-item>
        <el-form-item label="租金" prop="rent" v-if="form.isType != 5">
          <el-input v-model="form.rent" placeholder="请输入租金" />
        </el-form-item>
        <el-form-item label="转让费" prop="transferFee" v-if="form.isType != 5">
          <el-input v-model="form.transferFee" placeholder="请输入转让费" />
        </el-form-item>
<!--        <el-form-item label="转让标语" prop="areaTitle">-->
<!--          <el-input v-model="form.areaTitle" placeholder="请输入转让标语" />-->
<!--        </el-form-item>-->
        <el-form-item label="租金预算" prop="budgetId" v-if="form.isType == 5">
          <el-select v-model="form.budgetId" placeholder="请选择租金预算">
            <el-option
              v-for="item in budgetList"
              :key="item.id"
              :label="item.title"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="面积预算" prop="areaId"  v-if="form.isType == 5">
          <el-select v-model="form.areaId" placeholder="请选择面积预算" @change="areaListBtn">
            <el-option
              v-for="item in areaList"
              :key="item.id"
              :label="item.title"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="标题" prop="areaDetails">
          <el-input v-model="form.areaDetails" placeholder="请输入标题" />
        </el-form-item>

        <el-form-item label="是否急租" prop="isUrgentRental" v-if="form.isType == 5">
          <el-select v-model="form.isUrgentRental" placeholder="请选择是否急租">
            <el-option
              v-for="dict in dict.type.sys_yes_no"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>


<!--        <el-form-item label="是否发布" prop="isRelease">-->
<!--          <el-select v-model="form.isRelease" placeholder="请选择是否发布">-->
<!--            <el-option-->
<!--              v-for="dict in dict.type.sys_yes_no"-->
<!--              :key="dict.value"-->
<!--              :label="dict.label"-->
<!--              :value="dict.value"-->
<!--            ></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
        <el-form-item label="是否置顶" prop="isTop">
          <el-select v-model="form.isTop" placeholder="请选择是否置顶">
            <el-option
              v-for="dict in dict.type.sys_yes_no"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用户ID" prop="userId">
          <el-select v-model="form.userId" placeholder="请选择类型">
            <el-option
              v-for="item in userList"
              :key="item.id"
              :label="item.nickName"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否上线" prop="isShow">
          <el-select v-model="form.isShow" placeholder="请选择是否上线">
            <el-option
              v-for="dict in dict.type.sys_yes_no"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否支付" prop="isPay">
          <el-select v-model="form.isPay" placeholder="请选择是否支付">
            <el-option label="正常支付" value="0">正常支付</el-option>
            <el-option label="未支付" value="1">未支付</el-option>
            <el-option label="手动支付" value="2">手动支付</el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="排序" prop="numSoft">
          <el-input-number v-model="form.numSoft" :min="1" :max="9999" label="排序" size="mini"></el-input-number>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改垃圾站点信息对话框 -->
    <el-dialog title="上传站点" :visible.sync="uploadFileFlag" width="50%" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        :data="reTypeNum"
        accept=".csv"
        :headers="upload.headers"
        :action="upload.url"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" style="color:red" slot="tip">提示：允许导入"csv"格式文件！</div>
      </el-upload>
      <el-form>
        <el-form-item>
          <el-select v-model="reTypeNum.userId" placeholder="请选择整改状态" clearable>
            <el-option
              v-for="item in userList"
              :key="item.id"
              :label="item.nickName"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormPoint">确 定</el-button>
        <el-button @click="cancelFile">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAHousing, getAHousing, delAHousing, addAHousing, updateAHousing, logicDelAHousing } from "@/api/system/aHousing";
import {listADictShops, updateADictShops} from "@/api/system/aDictShops";
import { listADictAdvantageLable} from "@/api/system/aDictAdvantage";
import { listIwebshopAreasParentId } from "@/api/system/iwebshopAreas";
import { listADictShopsFourList } from "@/api/system/aDictShops";
import { listADictNatureTypeList } from "@/api/system/aDictNature";
import { listAUserAllList } from "@/api/system/aUser";
import { allAreaList } from "@/api/system/aDictArea";
import { allBudgetList } from "@/api/system/aDictBudget";
import { allAffiliation } from "@/api/system/aDictIndustryAffiliation";
import {getToken} from "@/utils/auth";

export default {
  name: "AHousing",
  dicts:['lease_type','sys_yes_no'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 房屋信息表格数据
      aHousingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        orderByColumn: 'create_time',
        isAsc: 'desc',
        isType: null,
        name: null,
        phone: null,
        region: null,
        picture: null,
        video: null,
        natureId: null,
        advanageId: null,
        isQuick: null,
        isLease: null,
        areaNum: null,
        rent: null,
        transferFee: null,
        areaTitle: null,
        areaDetails: null,
        visitNum: null,
        exposureNum: null,
        phoneNum: null,
        isShop: null,
        isUrgentRental: null,
        budgetId: null,
        areaId: null,
        isRelease: null,
        isReDetails: null,
        isTop: null,
        userId: null,
        isShow: null,
        numSoft: null,
        isPay:"0",
        isUpload:"0",
      },
      // 表单参数
      form: {
        advanageId:[],
      },
      // 表单校验
      rules: {
        isType: [
          { required: true, message: "类型不能为空", trigger: "change" }
        ],
        userId: [
          { required: true, message: "用户不能为空", trigger: "change" }
        ],
        name: [
          { required: true, message: "联系人不能为空", trigger: "blur" }
        ],
        phone:[
          { required: true, message: "联系电话不能为空", trigger: "blur" },
          {
            pattern: /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/,
            message: '手机号码格式不对，请重新输入', trigger: 'blur',
          },
        ],
        // areaNum:[
        //   { required: true, message: "转出面积不能为空", trigger: "blur" }
        // ],
        // rent:[
        //   { required: true, message: "租金不能为空", trigger: "blur" }
        // ],
        // transferFee:[
        //   { required: true, message: "转让费不能为空", trigger: "blur" }
        // ],
        areaTitle:[
          { required: true, message: "转让标语不能为空", trigger: "blur" }
        ]
      },
      //店铺类型
      shopList:[],
      //优势
      advantageList:[],
      checkAll: false,
      isIndeterminate: true,
      //地区数组
      iwebshopAreasList:[],
      iwebshopAreasLists:[],
      //房源
      fourList:[],
      //用途
      checkNa: false,
      isIndeterminateNa: true,
      typeListHg:[],
      userList:[],
      //面积
      areaList:[],
      //租金
      budgetList:[],
      //房源用途
      affiliationList:[],
      affiliationLists:[],
      industryIdList:[],
      //组合数据 --开始
      //区名称
      urbanName:"",
      //用途
      purposeName:"",
      //面积
      areaName:"",
      //优势
      facilityName:"",
      //房屋类型
      zdNatureName:"",
      //商铺名称
      zdShopName:"",
      //获取找店面积
      zdAreaName:"",
      //组合数据 --结束
      //上传csv ---- 开始
      uploadFileFlag:false,
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址  导入csv
        url: process.env.VUE_APP_BASE_API + "/system/aHousing/uploadFile",
      },
      reTypeNum:{
        userId: "",
      },
      //上传csv ---- 结束
    };
  },
  created() {
    this.getList();
    this.dictShopList();
    this.getAdvantList();
    this.iwebshopList();
    this.aDictShops();
    this.getUserList();
    this.getAllAreaList()
    this.getAllBudgetList();
    this.getAllAffiliation();
  },
  methods: {
    dictShopList(){
      this.loading = true;
      let queryParams={
        pageNum: 1,
        pageSize: 10,
      }
      listADictShops(queryParams).then(response => {
        this.shopList = response.rows;
        this.loading = false;
      });
    },
    getAdvantList(){
      this.loading = true;
      listADictAdvantageLable().then(response => {
        this.advantageList = response.data;
        this.loading = false;
      });
    },
    iwebshopList(){
      this.loading = true;
      listIwebshopAreasParentId().then(res => {
        this.iwebshopAreasLists = res.data;
        this.iwebshopAreasList = this.handleTree(res.data, "id", "parentId");
        this.iwebshopAreasList = this.handleDisable(this.iwebshopAreasList);
        this.loading = false;
      });
    },

    handleDisable(data) {
      data.forEach(item =>{
        if(item.children && item.children.length > 0){
          this.handleDisable(item.children)
        }else{
          item.leaf = true;
        }
      });
      return data;
    },

    aDictShops(){
      this.loading = true;
      listADictShopsFourList().then(response => {
        this.fourList = response.data;
        this.loading = false;
      });
    },
    getUserList(){
      this.loading = true;
      listAUserAllList().then(response => {
        this.userList = response.data;
        this.loading = false;
      });
    },
    getAllAreaList(){
      this.loading = true;
      allAreaList().then(response => {
        this.areaList = response.data;
        this.loading = false;
      });

    },
    getAllBudgetList(){
      this.loading = true;
      allBudgetList().then(response => {
        this.budgetList = response.data;
        this.loading = false;
      });
    },
    getAllAffiliation(){
      this.loading = true;
      allAffiliation().then(res => {
        this.affiliationLists = res.data;
        this.affiliationList= this.handleTree(res.data, "id", "parentId");
        this.loading = false;
      });
    },
    shopType(val){
      this.form.natureId = null;
      this.aDictNature(val)
      if (this.form.isType == 5){
        var ss ="";
        for (let z = 0; z <this.fourList.length ; z++){
          if (this.form.isShop == this.fourList[z].id){
            ss = this.fourList[z].title
          }
        }
        this.shopName = ss+"做";
        this.form.areaDetails = "";
        this.form.areaDetails = this.urbanName+this.shopName+this.zdNatureName;
      }
    },
    aDictNature(id){
      this.loading = true;
      let query = {
        shopId:id
      }
      listADictNatureTypeList(query).then(response => {
        this.typeListHg = response.data;
        this.loading = false;
      });
    },
    /** 查询房屋信息列表 */
    getList() {
      this.loading = true;
      listAHousing(this.queryParams).then(response => {
        this.aHousingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        isType: null,
        name: null,
        phone: null,
        region: null,
        picture: null,
        video: null,
        natureId: null,
        advanageId: null,
        isQuick: null,
        isLease: null,
        areaNum: null,
        rent: null,
        transferFee: null,
        areaTitle: null,
        areaDetails: null,
        visitNum: null,
        exposureNum: null,
        phoneNum: null,
        isShop: null,
        isUrgentRental: null,
        budgetId: null,
        areaId: null,
        isRelease: null,
        isReDetails: null,
        isTop: null,
        userId: null,
        createTime: null,
        updateTime: null,
        createBy: null,
        updateBy: null,
        delFlag: null,
        isShow: null,
        numSoft: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.dictShopList();
      this.getAdvantList();
      this.iwebshopList();
      this.aDictShops();
      this.getUserList();
      this.getAllAreaList()
      this.getAllBudgetList();
      this.getAllAffiliation();
      this.reset();
      this.form.adList = [];
      this.form.isType = this.shopList[0].id;
      this.shopType(this.form.isType);
      this.open = true;
      this.title = "添加房屋信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.dictShopList();
      this.getAdvantList();
      this.iwebshopList();
      this.aDictShops();
      this.getUserList();
      this.getAllAreaList()
      this.getAllBudgetList();
      this.getAllAffiliation();
      this.reset();
      this.form.adList = [];
      const id = row.id || this.ids
      getAHousing(id).then(response => {
        this.form = response.data;
        //店铺类型
        if (this.form.isType != null && this.form.isType != 5){
          this.shopType(this.form.isType);
        }
        if(this.form.isType == 5){
          this.shopType(this.form.isShop)
        }
        if(this.form.hIndustryId != null){
          this.industryIdList = this.form.hIndustryId.split(',');
        }

        this.$forceUpdate();
        this.open = true;
        this.title = "修改房屋信息";
      });
    },
    updateTimeBtn(row){
      updateAHousingTime(row.id).then(res => {
        this.$modal.msgSuccess("更新时间完毕");
        this.open = false;
        this.getList();
      });
    },
    /** 提交按钮 */
    submitForm() {
      var hIndustryId = "";
      var hIndustryName = "";
      for (var i=0; i<this.industryIdList.length;i++){
        console.log(this.industryIdList.length)
        if (i == this.industryIdList.length-1){
          hIndustryId += this.industryIdList[i]
        }else{
          hIndustryId += this.industryIdList[i]+",";
        }
      }

      for (let i = 0; i <this.industryIdList.length ; i++) {
        for (let z = 0; z <this.affiliationLists.length ; z++) {
          if(i == 2 && this.industryIdList[i] == this.affiliationLists[z].id){
            hIndustryName += this.affiliationLists[z].inName
          }else if(this.industryIdList[i] == this.affiliationLists[z].id ){
            hIndustryName += this.affiliationLists[z].inName+","
          }
        }
      }

      this.form.hindustryId = hIndustryId;
      this.form.hindustryName = hIndustryName;

      this.$refs["form"].validate(valid => {
        if (valid) {
          var ss = "";
          for (var i = 0; i<this.form.regionList.length;i++){
            for (var o = 0; o < this.iwebshopAreasLists.length; o++) {
              if (i == 2 && this.form.regionList[i] == this.iwebshopAreasLists[o].id) {
                ss += this.iwebshopAreasLists[o].label;
              }else if (this.form.regionList[i] == this.iwebshopAreasLists[o].id) {
                ss += this.iwebshopAreasLists[o].label+"/";
              }
            }
          }
          this.form.regionAllName = ss;
          this.loading = true;
          if(this.form.isType == 5){
            this.form.isLease = "3";
          }
          if (this.form.regionList.length == 3){
            this.form.provinceId = this.form.regionList[0];
            this.form.cityId = this.form.regionList[1];
            this.form.region = this.form.regionList[2];
          }else{
            this.$modal.msgError("请选择到区！");
            return;
          }

          let adId = "";
          for (var o = 0 ; o<this.form.adList.length ;o++){
            if (o == this.form.adList.length -1){
              adId +=this.form.adList[o]
            }else{
              adId +=this.form.adList[o]+","
            }
          }

          this.form.advanageId = adId;

          if (this.form.id != null) {
            updateAHousing(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAHousing(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除房屋信息编号为"' + ids + '"的数据项？').then(function() {
        return logicDelAHousing(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/aHousing/export', {
        ...this.queryParams
      }, `aHousing_${new Date().getTime()}.xlsx`)
    },
    handleCheckedCitiesChange(value) {
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.advantageList.length;
      this.isIndeterminate = checkedCount > 0 && checkedCount < this.advantageList.length;

      var ss = "";
      for (let i = 0; i <this.form.adList.length ; i++) {
        for (let z = 0; z <this.advantageList.length ; z++) {
         if(this.form.adList[i] == this.advantageList[z].id){
            ss += this.advantageList[z].title+","
          }
        }
      }
      this.form.areaDetails = "";
      this.facilityName = ss;
      this.form.areaDetails = this.urbanName+this.areaName+this.purposeName+this.facilityName;

      this.$forceUpdate();
    },
    handleChangeIsShow(row){
      if (row.isShow == 0 && row.isPay != 0){
        row.isPay = "2";
      }
      this.loading = true;
      updateAHousing(row).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.loading = false;
        this.getList();
      }).catch(() => {
        this.loading = false;
        this.getList();
      });
    },
    handleChange(row){
      this.loading = true;
      updateAHousing(row).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.loading = false;
        this.getList();
      }).catch(() => {
        this.loading = false;
        this.getList();
      });
    },
    areaBtn(val) {
      for (var o = 0; o < this.iwebshopAreasLists.length; o++) {
        if (val[2] == this.iwebshopAreasLists[o].id) {
          if (this.form.isType != 5) {
            this.urbanName = this.iwebshopAreasLists[o].label;
            this.form.areaDetails = "";
            this.form.areaDetails = this.urbanName + this.areaName + this.purposeName + this.facilityName;
          }else  if (this.form.isType == 5) {
            this.urbanName = "找" + this.iwebshopAreasLists[o].label;
            this.form.areaDetails = "";
            this.form.areaDetails = this.urbanName + this.zdNatureName + this.zdShopName + this.zdAreaName;
          }
        }
      }
    },
    affBtn(){
      var ss = "";
      for (let i = 0; i <this.industryIdList.length ; i++) {
        for (let z = 0; z <this.affiliationLists.length ; z++) {
           if(i == 2 && this.industryIdList[i] == this.affiliationLists[z].id){
             ss += this.affiliationLists[z].inName
           }else if(this.industryIdList[i] == this.affiliationLists[z].id ){
              ss += this.affiliationLists[z].inName+","
            }
        }
      }
      this.purposeName = ss;
      this.form.areaDetails = "";
      this.form.areaDetails = this.urbanName+this.areaName+this.purposeName+this.facilityName;
    },
    areaBtnNum(val){
      this.areaName = val+"㎡";
      this.form.areaDetails = "";
      this.form.areaDetails = this.urbanName+this.areaName+this.purposeName+this.facilityName;
    },
    backIsPay(row){
      row.isPay = "1";
      row.isShow = "1";
      row.payTime = "";
      updateAHousing(row).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.loading = false;
        this.getList();
      }).catch(() => {
        this.loading = false;
        this.getList();
      });
    },
    natureBtn(){
      var ss ="";
      for (let z = 0; z <this.typeListHg.length ; z++){
        if (this.form.natureId == this.typeListHg[z].id){
          ss = this.typeListHg[z].title
        }
      }
      this.zdNatureName = ss+"，有店可与我联系哟";
      this.form.areaDetails = ""
      this.form.areaDetails = this.urbanName+this.zdAreaName+this.shopName+this.purposeName+this.zdNatureName;
    },
    areaListBtn(val){
      var ss ="";
      for (let z = 0; z <this.areaList.length ; z++){
        if (val == this.areaList[z].id){
          ss = this.areaList[z].title
        }
      }
      this.zdAreaName = ss
      this.form.areaDetails = "";
      this.form.areaDetails = this.urbanName+this.zdAreaName+this.shopName+this.purposeName+this.zdNatureName;
    },

    /** 导入按钮操作 ---------------开始 */
    uploadFile(){
      this.uploadFileFlag = true;
    },
    cancelFile(){
      this.uploadFileFlag = false;
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFormPoint() {
      this.$refs.upload.submit();
    },
    /** 导入按钮操作 ---------------结束 */
  }
};
</script>
